

 var information={
    currentPage:1,	
  	totalPage:1  	
  };
 var chooseId=0;
$(function(){
  var endId=[];
  var insertid;
  var deleteid;
  initTaskDis();
  requestSort();
  requestRefer(information);//已提交数据
  //跳转到详情界面
  $(document).on("click",".detail",function(){
	  	var id= $(this).attr("data-id");
		var menuId=$("#menu-container").attr("menu-id");
		window.location.href = '../information/subDetailInfo.jsp?menuId='+menuId+'&detailId=' + id;
  })
 $(document).on("click",".input-task-finsh-context",function(){
//	 var id= $(this).attr("data-id");	
//	 var account= $(this).attr("data-account");	
//	 $("#modal-show-account").text(account);
//	 $("#dispatch-task-modal").modal("show");
//	 $("#dispatch-flowId option").each(function(){
//		 if(($(this).val()>=$(".input-task-finsh-context").attr("data-flowId"))&&$(this).val()!=null){
//			 $(this).hide();
//		 }
//	 });
//	 $("#btn-modal-disptach-ok").attr("data-id",id);
	 var id= $(this).attr("data-id");
	 var menuId=$("#menu-container").attr("menu-id");
	 window.location.href='timeOutDeploy.jsp?updateId=' + id+"&menuId="+menuId;
  })
  
   $("#btn-modal-disptach-ok").click(function(){
	   var id= $(this).attr("data-id");	
	   var flowid=$("#dispatch-flowId").val();	
	   YuXi.util.get("DispatchInfo/dispatchInfoToAny.do",{infoId:id,flowId:flowid},function(data){
		   if(data.status){
			   myTool.alert({
				   title:data.subType,
				   context:data.msg
			   });
		   }else{
			   myTool.alert({
				   title:data.subType+"["+data.errorCode+"]",
				   context:data.msg+"[错误代码:"+data.errorCode+']'
			   });
		   }
	   });
  })
  
  $("#btn-information-info").click(function(){firstSearch();})  
  
  $(document).on("click",".insert-task",function(){
	  insertid="infoId="+$(this).attr("data-id");
	  $("#Mymodal").modal('show');
  });
 ;
  //提交模态框按钮  
  $("#btnSure").click(function(){	
	  requestSure(insertid);//调用提交方法;
  })

  //分页，首页
  $("#headPage").click(function(){
	information.currentPage=1;
  	$("#totalPage").html(information.currentPage+"/"+information.totalPage);
  	requestRefer(information);
  })
  

  //分页，尾页
  $("#endPage").click(function(){
  	$("#totalPage").html(information.totalPage+"/"+information.totalPage);
  	information.currentPage=information.totalPage;
  	requestRefer(information);
  })
  //分页，上一页
  $("#prevPage").click(function(){
  	if(information.currentPage<=1)
  	{
  		information.currentPage=1;
  	}
  	else
  	{
  		information.currentPage=information.currentPage-1;
  		$("#totalPage").html(information.currentPage+"/"+information.totalPage);  
  		requestRefer(information);
  	}

 })
 
  //分页，下一页
   $("#nextPage").click(function(){
  	
  	if(information.currentPage>=information.totalPage)
  	{
  		information.currentPage=information.currentPage;
  	}
  	else
  	{
  		information.currentPage=information.currentPage+1;
  		$("#totalPage").html(information.currentPage+"/"+information.totalPage);
  		requestRefer(information);
  	}
  	
  })
  
})

//提交按钮
function requestSure(id){
	 
	  var url="TaskDispatchFilter/taskSubToTaskFinish.do";//提交的地址
	  YuXi.util.get(url,id,function(data){
		  if(data.status)
		  {
			  $("#successmodel").modal('show');
		  }
		  else
		  {
			 
			  $("#badmodal").modal('show');
		  }
	  },function(){
		  $("#badmodal").modal('show');
	  })
}

//向后台请求的信息数据
function requestRefer(data){
	var url="InformationDispatch/getAllTimeOutInfoList.do";
	YuXi.util.get(url,data,function(data){	 
		object=data.list;
		information.totalPage=data.totalPage;
		information.page=data.currentPage;
		$("#totalPage").text(information.page+"/"+information.totalPage);
		$("#table1body").html("");
		for(var i=0;i<object.length;i++)
		{
			if( object[i].informationProfile.length>15)
				object[i].informationProfile= object[i].informationProfile.substring(0,15)+"...";
			var time=YuXi.getTime.get(object[i].createTime);
			
			var dtext="";
			
			dtext="&nbsp;&nbsp;<a data-flowId="+object[i].flowId+" data-id="+object[i].id+" href='javascript:void(0);' data-id='"+object[i].id+"'data-account='"+object[i].informationAccount+"' class='input-task-finsh-context'>调配信息</a>";
			
			var html="<tr ><td>"+ object[i].informationAccount+"</td><td >"+object[i].informationProfile+"</td>"+
			
			"<td >"+object[i].informationClassificationNames+"</td>"+
			"<td >"+object[i].informationSortNames+"</td>"+
			"<td >"+object[i].informationSourceNames+"</td>"+
			"<td >"+object[i].safetyPortNames+"</td>"+
			"<td >"+time+"</td>"+
			"<td><a href='javascript:void(0);' data-id="+object[i].id+" class='detail'>详情</a>"+dtext+"&nbsp;&nbsp;</td></tr>";
			
			$("#table1body").append(html);
		}
		
	YuXi.graded.get();
	},function(){});
  

}
$("#firstSearch").click(function(){
	firstSearch();
});
//简介，分级，渠道，状态，时间（今天,一周...）查找
function firstSearch()
{	
	var information={};
	var curFlowText = $(".reSearchFlow option:selected").val();
		curFlowText == null ? "" : information.curFLow = curFlowText; //当前状态
		information.inputName=$("#requestName").val();
	if($("#profile").val()!=null&&$("#profile").val()!="")
		information.key=$("#profile").val();//简介

	information.key = $("#profile").val(); //简介
	if($("#profile").val()=="请输入简介关键字")
	{
		information.key="";
	}
	information.safetyPortId=$(".rePort option:selected").val();//分口
	information.prisonId=$(".reDepartment option:selected").val();//部门
	var inputNameFlag=$("#requestName").val();//参与人
	//alert(inputNameFlag);
		if(inputNameFlag=="请输入参与人姓名或警号")
		{
			information.intputName="";
			
		}
		else
		{ 
			var flag=/^[(-?\d+\.\d+)|(-?\d+)|(-?\.\d+)]+$/.test(inputNameFlag + '');
			
			if(!flag)
			{
				information.intputName=inputNameFlag;
			}
			else
			{
				information.intputNumber=inputNameFlag;
			}
		}
	//alert(information.intputNumber);	
	if($(".reSearchSourceSel option:selected").val()!="null"&&$(".reSearchSourceSel option:selected").val()!="")
		information.informationSource=$(".reSearchSourceSel option:selected").val();//来源渠道
	if($(".pes option:selected").val()!="null"&&$(".pes option:selected").val()!="")
		information.informationLv=$(".pes option:selected").val();//分级
	if($(".reSearchsort option:selected").val()!="null"&&$(".reSearchsort option:selected").val()!="")
		information.informationSort=$(".reSearchsort option:selected").val();//分类
	//var value=$(".valTime option:selected").val();
	var array=[];	
	var starTime=$("#starTime").val();
	var endTime=$("#endTime").val();
	array=YuXi.timestamp.get(starTime,endTime,null);	
	if(array[0]!=null)
		information.startTimestamp = array[0];
	if(array[1]!=null)
		information.endTimestamp = array[1];

	information.currentPage=1;
	////console.log(JSON.stringify(information));
	requestRefer(information);
	
	
}

function initTaskDis(){
	
	
	 YuXi.util.get("getAllInformationClassification.do",null,function(data){
		 if(data.status){
			 var obj=data.object;
			 for(var i=0;i<obj.length;i++){
				 $(".reSearchpes").append("<option value='"+obj[i].id+"' >"+obj[i].name+"</option>");
			 }
			 
		 }
	 });
	 
	 YuXi.util.get("getAllInfomationSource.do",null,function(data){
		 if(data.status){
			 var obj=data.object;
			 for(var i=0;i<obj.length;i++){
				 $(".reSearchSource").append("<option value='"+obj[i].id+"' >"+obj[i].name+"</option>");
			 }
			 
		 }
	 });
	 
	 
	 YuXi.util.get("getAllInformationPort.do","null",function(data){
		 if(data.status){
			 var obj=data.object;
			 for(var i=0;i<obj.length;i++){
				 $(".task-port").append("<option value='"+obj[i].id+"' >"+obj[i].portName+"</option>");
			 }
			 
		 }
	 });
	 YuXi.util.get("getAllTasCompletion.do",null,function(data){
		 if(data.status){
			 var obj=data.object;
			 for(var i=0;i<obj.length;i++){				
				 $("#infoAndS-container").append("<input type='radio' name='infoLv' value='"+obj[i].id+"' >"+obj[i].name+"</input>");
			 }
			 
		 }
	 });
	 
	 YuXi.util.get("getAllInformationQuality.do",null,function(data){
		 if(data.status){
			 var obj=data.object;
			 for(var i=0;i<obj.length;i++){				
				 $("#taskFinsh-container").append("<input type='radio' name='taskLv' value='"+obj[i].id+"' >"+obj[i].name+"</input>");
			 }
			 
		 }
	 });
	
	
}


//向后台请求分类信息
function requestSort(){		
	
	var url="getAllInfomationSort.do";//分类地址
	var data={};
	var object={};
	data=YuXi.util.get(url,"null",function(data){
		object=data.object;
		//用data循环添加分类信息
		for(var i=0;i<object.length;i++)
		{
			var html="<option  value="+object[i].id+" >"+object[i].name+"</option>";
			$(".reSearchsort").append(html);
		}
	},function(){
		
	});//请求数据
	
}
